Attributed String Creator app icon

Attributed String Creator

Style text the way you want it to look in your app, and get the NSAttributedString code that builds it. Swift or Objective-C, for iOS or macOS.

Download Attributed String Creator on the Mac App Store $9.99 · £9.99 · Buy once, no subscription

How it works

Format it. Copy the code.

Writing attributed strings by hand means counting characters and declaring every font and colour yourself. Attributed String Creator writes that code while you format the text, and keeps it up to date with every change.

Attributed String Creator with a styled sale banner in the editor and the Swift code for it underneath
  1. Bring in your textType it, paste it, or open an RTF, Word or text file. The code appears straight away.
  2. Format it like any Mac textFonts, sizes, bold, alignment and spacing, from the format bar, the Fonts panel or the Format menu.
  3. Colour it inEvery colour, underline and strikethrough gets declared, with the exact range it covers.
  4. Swift or Objective-COne click switches the language.
  5. iOS or macOSGet UIFont and UIColor, or NSFont and NSColor.
  6. Variable or methodName it, and wrap it in a function if you like.
  7. Copy the codePaste it into Xcode and assign it to a label, a text view or a button.

The code

Code you'd write yourself

This is the code Attributed String Creator made for the sale banner above, exactly as it came out of the app.

myString · Swift · iOSGenerated
// Create the attributed stringlet myString = NSMutableAttributedString(string:"Weekend Sale\nEverything is 30% off until Sunday.") // Declare the fontslet myStringFont1 = UIFont(name:"AvenirNext-Bold", size:30.0)!let myStringFont2 = UIFont(name:"AvenirNext-Regular", size:17.0)!let myStringFont3 = UIFont(name:"AvenirNext-Bold", size:17.0)! // Declare the colorslet myStringColor1 = UIColor(red: 0.140555, green: 0.091569, blue: 0.550404, alpha: 1.000000)let myStringColor2 = UIColor(red: 0.901886, green: 0.311835, blue: 0.084182, alpha: 1.000000) // Declare the paragraph styleslet myStringParaStyle1 = NSMutableParagraphStyle()myStringParaStyle1.alignment = NSTextAlignment.center  // Create the attributes and add them to the stringmyString.addAttribute(NSAttributedString.Key.foregroundColor, value:myStringColor1, range:NSRange(location: 0, length: 13))myString.addAttribute(NSAttributedString.Key.paragraphStyle, value:myStringParaStyle1, range:NSRange(location: 0, length: 13))myString.addAttribute(NSAttributedString.Key.font, value:myStringFont1, range:NSRange(location: 0, length: 13))myString.addAttribute(NSAttributedString.Key.paragraphStyle, value:myStringParaStyle1, range:NSRange(location: 13, length: 14))myString.addAttribute(NSAttributedString.Key.font, value:myStringFont2, range:NSRange(location: 13, length: 14))myString.addAttribute(NSAttributedString.Key.foregroundColor, value:myStringColor2, range:NSRange(location: 27, length: 7))myString.addAttribute(NSAttributedString.Key.paragraphStyle, value:myStringParaStyle1, range:NSRange(location: 27, length: 7))myString.addAttribute(NSAttributedString.Key.font, value:myStringFont3, range:NSRange(location: 27, length: 7))myString.addAttribute(NSAttributedString.Key.paragraphStyle, value:myStringParaStyle1, range:NSRange(location: 34, length: 14))myString.addAttribute(NSAttributedString.Key.font, value:myStringFont2, range:NSRange(location: 34, length: 14))
  • Declared once, used everywhereEach font, colour and paragraph style gets one variable, named after your string, however many times the text uses it.
  • Grouped and in orderFonts, then colours, then paragraph styles, then the attributes. Change a size or a colour in one place.
  • Exact rangesEvery attribute is added with the range it covers, so nothing needs counting. Or turn on Declare variables with rangeOfString in the Options menu and the ranges are found by searching the text instead.
  • Defaults left outParagraph styles only set what you changed. Verbose Paragraph Properties declares the lot, and you choose whether tab stops are included.

Features

Everything rich text can do

Fonts

Warns you about missing fonts

The warning under the code: CAUTION: The following font you are using isn't part of the iOS SDK: SignPainter-HouseScript. Find out how to import this in the help section.

Not every Mac font is on iOS

Attributed String Creator knows which fonts come with iOS. If your text uses one that doesn't, it tells you which, and gives you the exact name to use once you've added the font to your app.

How to add a custom font to an iOS app →

A look inside

Your text above, your code below

Light or dark, it follows your Mac's appearance.

Get it

Buy it once

Attributed String Creator Pro

$9.99 · £9.99, a one-off purchase

  • No subscription and no limits
  • Swift and Objective-C, for iOS and macOS
  • Free updates through the Mac App Store
Download Attributed String Creator Pro on the Mac App Store

Want to try it first? The free version works on up to 40 characters at a time.

Getting started? The help guide covers every control, the Options menu and adding custom fonts. Read the help guide → Formatting dates too? Date Format Creator builds date format strings for Swift and Objective-C. See Date Format Creator →

Details